﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iLangl.Model.Rules
{
	public class ValidateContent : IValidation
	{
		ContentEntity content;
		#region IValidation Members

		public IList<IError> Validate(object item)
		{
			List<IError> result = new List<IError>();

			if (!(item is ContentEntity))
			{
				result.Add(new Error(
					"Validation Failed",
					String.Format("Expected type ='Content' instead of {0}", item.GetType()),
					eSeverity.High));

				return result;
			}

			content = item as ContentEntity;

			if (string.IsNullOrEmpty(content.Id))
			{
				result.Add(new Error(
		"Project Content Identity is not Specified!",
		"Project.Content.Id is required field!",
		eSeverity.Critical));
			}

			if (string.IsNullOrEmpty(content.Name))
			{
				result.Add(new Error(
		"Project Content Name is not specified!",
		"Project.Conent.Name is required field!",
		eSeverity.High));
			}

			if (string.IsNullOrEmpty(content.Content))
			{
				result.Add(new Error(
		"Project Content Content is not specified!",
		"Project.Conent.Content is required field!",
		eSeverity.High));
			}

			if (string.IsNullOrEmpty(content.Type))
			{
				result.Add(new Error(
		"Project Content Type is not specified!",
		"Project.Conent.Type is required field!",
		eSeverity.Low));
			}

			if (content.Language == null)
			{
				result.Add(new Error(
		"Project Content Language is not specified!",
		"Project.Conent.Language is required field!",
		eSeverity.High));
			}
			else
			{
				if (string.IsNullOrEmpty(content.Language.LanguageId))
				{
					result.Add(new Error(
		"Project Content Language Id is not specified!",
		"Project.Conent.Language.Id is required field!",
		eSeverity.High));
				}


				if (string.IsNullOrEmpty(content.Language.LanguageName))
				{
					result.Add(new Error(
		"Project Content Language Name is not specified!",
		"Project.Conent.Language.Name is required field!",
		eSeverity.Low));
				}
			}

			return result;
		}

		#endregion
	}
}
